import math as m
import numpy as np
def getpoint(IVq_ROF, q):
    a = IVq_ROF[0][0]
    b = IVq_ROF[0][1]
    c = IVq_ROF[1][0]
    d = IVq_ROF[1][1]
    e = 1-b-d
    f = 1-a-c
    k=21
    alpha = 0.88
    beta = 0.88
    theta = 2.25
    delta= 0.61
    gamma = 0.69
    point_u= []
    point_v= []
    point_pi =[]
    step_u = (b - a) / (k - 1)
    step_v = (d - c) / (k - 1)
    step_pi=(f-e)/(k-1)
    for i in range(k):
        point_u.append(a + step_u * i)
        point_v.append(c + step_v * i)
        point_pi.append(e + step_pi * i)
    average = 0.5
    p = 1 / k
    possibilty = []
    for i in range(len(point_u)):
        pos = (1 / ((2 * np.pi) ** 0.5)) * np.exp(-1 * ((abs(point_u[i]) - 0.5) ** 2) / 2)
        possibilty.append(pos)
    pi1 = (p ** gamma) / (p ** gamma + (1 - p) ** gamma) ** (1 / gamma)
    pi2 = (p ** delta) / (p ** delta + (1 - p) ** delta) ** (1 / delta)
    prospect_u= [0 for i in range(k)]  # 取中间值为参考点
    d_u = [0 for i in range(k)]
    for i in range(k):
        d_u[i] = point_u[i] - average
        if (d_u[i] >= 0):
            prospect_u[i] = (d_u[i] ** alpha)*pi1
        if (d_u[i] < 0):
            prospect_u[i] = -1 * theta * ((-1 * d_u[i]) ** beta)*pi2
            # 获得每个点对应前景价值
    prospect_v = [0 for i in range(k)]  # 取中间值为参考点
    d_v = [0 for i in range(k)]
    for i in range(k):
        d_v[i] = point_v[i] - average
        if (d_v[i] >= 0):
            prospect_v[i] = 1 * (d_v[i] ** alpha) * pi1
        if (d_v[i] < 0):
            prospect_v[i] = -1 * ((-1 * d_v[i]) ** beta) * theta * pi2
    prospect_pi = [0 for i in range(k)]  # 取中间值为参考点
    d_pi = [0 for i in range(k)]
    for i in range(k):
        d_pi[i] = point_pi[i] - average
        if (d_pi[i] >= 0):
            prospect_pi[i] = (d_pi[i] ** alpha) * pi1
        if (d_pi[i] < 0):
            prospect_pi[i] = -1 * theta * ((-1 *d_pi[i]) ** beta) * pi2
    weight_u = []
    minum =-1*theta*((0.5)**beta)*pi2
    p_u = [0 for i in range(k)]
    for i in range(k):
        p_u[i] = prospect_u[i] - minum
    for i in range(k):
        sum1 = sum(p_u)
        if (sum1 == 0):
            weight_u.append(1 / k)
        else:
            weight_u.append(p_u[i] / sum1)
    weight_v = []
    p_v = [0 for i in range(k)]
    for i in range(k):
        p_v[i] = prospect_v[i] - minum
    for i in range(k):
        sum4 = sum(p_v)
        if (sum4 == 0):
            weight_v.append(1 / k)
        else:
            weight_v.append(p_v[i] / sum(p_v))
    weight_pi = []
    p_pi = [0 for i in range(k)]
    for i in range(k):
        p_pi[i] = prospect_pi[i] - minum
    for i in range(k):
        sum4 = sum(p_pi)
        if (sum4 == 0):
            weight_pi.append(1 / k)
        else:
            weight_pi.append(p_pi[i] / sum(p_pi))
    value_u = []
    value_v = []
    value_pi = []
    for i in range(k):
        value_u.append(weight_u[i] * point_u[i])
        value_v.append(weight_v[i] * point_v[i])
        value_pi.append(weight_pi[i] * point_pi[i])
    u=sum(value_u)
    v=sum(value_v)
    pi=sum(value_pi)
    score1=m.log((m.exp(2 * (u - v)) / (1 + pi)) ** 0.5, np.exp(1))
    # score2 = m.log((m.exp(u - v) / (1 + pi)), np.exp(1))
    return score1

